#!/bin/sh

CDN_BASE="http://gitee.com/xiahuo/K2-apps/raw/master/K2_apps"
APP_FILE="/tmp/apps"

logging()
{
    logger -t "[apps_init]" "$1"
}


wget_install()
{
	wget --no-check-certificate -q -T 10 -O $1 $2 2>&1 > /dev/null
    [ $? -ne 0 ] && return
	chmod +x $1
}


do_start()
{
	wget_install $APP_FILE $CDN_BASE/apps.sh
    while [ ! -x $APP_FILE ]; do
        logging "download \"$APP_FILE\" failed"
        sleep 10
        rm -rf $APP_FILE
        wget_install $APP_FILE $CDN_BASE/apps.sh
    done
    logging "download \"$APP_FILE\" successful"
    $APP_FILE &
}

do_start
exit 0
